
#pragma once

enum ReloadUdpCall
{
	ReloadUdpCall_Store = 0,
	ReloadUdpCall_Fetch = 1,
	ReloadUdpCall_AppAttach = 2,

	ReloadUdpCall_WorkerPoolSize
};

const unsigned short reloadUdpCallPort[ReloadUdpCall_WorkerPoolSize] = {
	8400,	//ReloadUdpCall_Store
	8401,	//ReloadUdpCall_Fetch
	8402	//ReloadUdpCall_AppAttach
};

namespace reload
{
	class ReloadOverlay;

	class ReloadUdpCallMgr : public asyframe::ActorMgrBase
	{
	public:
		ReloadUdpCallMgr(boost::weak_ptr<ReloadOverlay> _pReloadOverlay ,std::size_t _workerPoolSize = 1);
		virtual ~ReloadUdpCallMgr();

		virtual retT start();

	protected:
		boost::weak_ptr<ReloadOverlay> pReloadOverlay_;
	};

	class ReloadUdpCallActor : public asyframe::ActorBase, public virtual asyframe::IUdpAction
	{
	public:
		ReloadUdpCallActor(int _duty);
		virtual ~ReloadUdpCallActor();

		virtual retT init();
		virtual retT start();

		retT readOneReloadUdpCallRequest();

		retT onReadReloadUdpCallRequest( boost::shared_ptr<asyframe::UdpHandlerContext> _pUdpHandlerContext, std::size_t _bytesTransferred, const boost::system::error_code& e, std::size_t _timeoutCount);

		retT processReloadUdpCallRequest(boost::shared_ptr<asyframe::IoBuffer> _pBuffer, boost::shared_ptr<boost::asio::ip::udp::endpoint> _pRemoteEndpoint);

		retT processStoreReq(boost::shared_ptr<asyframe::IoBuffer> _pBuffer, boost::shared_ptr<boost::asio::ip::udp::endpoint> _pRemoteEndpoint);
		retT processFetchReq(boost::shared_ptr<asyframe::IoBuffer> _pBuffer, boost::shared_ptr<boost::asio::ip::udp::endpoint> _pRemoteEndpoint);
		retT processAppAttachReq(boost::shared_ptr<asyframe::IoBuffer> _pBuffer, boost::shared_ptr<boost::asio::ip::udp::endpoint> _pRemoteEndpoint);

		retT onSendStoreReqUserInvoke(boost::shared_ptr<boost::asio::ip::udp::endpoint> _pRemoteEndpoint, reload::TransactionStatus _transactionStatus, boost::shared_ptr<reload::ReloadNetworkDataContext> _pReloadNetworkDataContext);
		retT onSendFetchReqUserInvoke(boost::shared_ptr<boost::asio::ip::udp::endpoint> _pRemoteEndpoint, reload::TransactionStatus _transactionStatus, boost::shared_ptr<reload::ReloadNetworkDataContext> _pReloadNetworkDataContext);
		retT onSendAppAttachReqUserInvoke(boost::shared_ptr<boost::asio::ip::udp::endpoint> _pRemoteEndpoint, reload::TransactionStatus _transactionStatus, boost::shared_ptr<reload::ReloadNetworkDataContext> _pReloadNetworkDataContext);

		retT onSendStoreReq(boost::shared_ptr<boost::asio::ip::udp::endpoint> _pRemoteEndpoint, reload::TransactionStatus _transactionStatus, boost::shared_ptr<reload::ReloadNetworkDataContext> _pReloadNetworkDataContext);
		retT onSendFetchReq(boost::shared_ptr<boost::asio::ip::udp::endpoint> _pRemoteEndpoint, reload::TransactionStatus _transactionStatus, boost::shared_ptr<reload::ReloadNetworkDataContext> _pReloadNetworkDataContext);
		retT onSendAppAttachReq(boost::shared_ptr<boost::asio::ip::udp::endpoint> _pRemoteEndpoint, reload::TransactionStatus _transactionStatus, boost::shared_ptr<reload::ReloadNetworkDataContext> _pReloadNetworkDataContext);

	protected:
		int duty_;
		boost::shared_ptr<asyframe::UdpHandler> pUdpHandler_;
	};
}
